VERSION 5.00
Begin VB.Form frmCompany 
   AutoRedraw      =   -1  'True
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Company Details"
   ClientHeight    =   4710
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6030
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4710
   ScaleWidth      =   6030
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtUSR_PCODE 
      Height          =   285
      Left            =   2040
      TabIndex        =   10
      Text            =   "USR_PCODE"
      Top             =   3720
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_ADDRESS_3 
      Height          =   285
      Left            =   2040
      TabIndex        =   9
      Text            =   "USR_ADDRESS_3"
      Top             =   3360
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_ADDRESS_2 
      Height          =   285
      Left            =   2040
      TabIndex        =   8
      Text            =   "USR_ADDRESS_2"
      Top             =   3000
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_ADDRESS_1 
      Height          =   285
      Left            =   2040
      TabIndex        =   7
      Text            =   "USR_ADDRESS_1"
      Top             =   2640
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_EMAIL 
      Height          =   285
      Left            =   2040
      TabIndex        =   6
      Text            =   "USR_EMAIL"
      Top             =   2280
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_FAX 
      Height          =   285
      Left            =   2040
      TabIndex        =   5
      Text            =   "USR_FAX"
      Top             =   1920
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_TELEPHONE 
      Height          =   285
      Left            =   2040
      TabIndex        =   4
      Text            =   "USR_TELEPHONE"
      Top             =   1560
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_VAT_NO 
      Height          =   285
      Left            =   2040
      TabIndex        =   2
      Text            =   "USR_VAT_NO"
      Top             =   840
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_REGISTRATION 
      Height          =   285
      Left            =   2040
      TabIndex        =   1
      Text            =   "USR_REGISTRATION"
      Top             =   480
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_CELL 
      Height          =   285
      Left            =   2040
      TabIndex        =   3
      Text            =   "USR_CELL"
      Top             =   1200
      Width           =   3855
   End
   Begin VB.TextBox txtUSR_COMPANY 
      Height          =   285
      Left            =   2040
      TabIndex        =   0
      Text            =   "USR_COMPANY"
      Top             =   120
      Width           =   3855
   End
   Begin VB.CommandButton cmdUpdate 
      Caption         =   "&Update"
      Height          =   375
      Left            =   4680
      TabIndex        =   12
      Top             =   4200
      Width           =   1215
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "Postal Code"
      Height          =   255
      Left            =   240
      TabIndex        =   22
      Top             =   3720
      Width           =   1695
   End
   Begin VB.Label Label10 
      Alignment       =   1  'Right Justify
      Caption         =   "Address Line 2"
      Height          =   255
      Left            =   240
      TabIndex        =   21
      Top             =   3000
      Width           =   1695
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "Address Line 3"
      Height          =   255
      Left            =   240
      TabIndex        =   20
      Top             =   3360
      Width           =   1695
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "Address Line 1"
      Height          =   255
      Left            =   240
      TabIndex        =   19
      Top             =   2640
      Width           =   1695
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "Email Address"
      Height          =   255
      Left            =   0
      TabIndex        =   18
      Top             =   2280
      Width           =   1935
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "Fax Number"
      Height          =   255
      Left            =   0
      TabIndex        =   17
      Top             =   1920
      Width           =   1935
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "Telephone Number"
      Height          =   255
      Left            =   0
      TabIndex        =   16
      Top             =   1560
      Width           =   1935
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "VAT #:"
      Height          =   255
      Left            =   120
      TabIndex        =   15
      Top             =   840
      Width           =   1815
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "Company Registration"
      Height          =   255
      Left            =   0
      TabIndex        =   14
      Top             =   480
      Width           =   1935
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "Cell Phone Number"
      Height          =   255
      Left            =   120
      TabIndex        =   13
      Top             =   1200
      Width           =   1815
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "Company Name"
      Height          =   255
      Left            =   120
      TabIndex        =   11
      Top             =   120
      Width           =   1815
   End
End
Attribute VB_Name = "frmCompany"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'==================================================================================
'Copyright (c) 2003, Andrew Jeremy Gargan (ajg@osite.co.za), Terence Leslie Van Zyl (tvz@osite.co.za)
'
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification,
'are permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list
'of conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this
'list of conditions and the following disclaimer in the documentation and/or other
'materials provided with the distribution.
'
'Neither the name of the <ORGANIZATION> nor the names of its contributors may be
'used to endorse or promote products derived from this software without specific
'prior written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
'ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
'WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
'IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
'INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
'BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
'LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
'OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
'OF THE POSSIBILITY OF SUCH DAMAGE.
'===================================================================================

Private Sub cmdUpdate_Click()
    update
End Sub

Private Sub Form_Load()
    clear_form
    Fill_Form
End Sub

Private Sub update()
    Dim lvarControl As Control
    Dim lvarQuery As String
    Dim lvarTemp As String
    
    lvarQuery = "UPDATE USER SET "
    
    For Each lvarControl In Controls
        'MsgBox lvarControl.Name
        If TypeName(lvarControl) = "TextBox" And Trim(UCase(lvarControl.Name)) Like "TXTUSR*" Then
            If VarType(Me(lvarControl.Name)) = vbObject Then
                lvarTemp = Trim(Mid(lvarControl.Name, 4)) & "_" & Trim(Str(lvarControl.index + 1))
            Else
                 lvarTemp = Trim(Mid(lvarControl.Name, 4))
            End If
            
            If lvarControl = "" Then
                lvarQuery = lvarQuery & lvarTemp & "= NULL," & vbCrLf
            Else
                lvarQuery = lvarQuery & lvarTemp & "=""" & Replace(lvarControl.Text, """", """""") & """," & vbCrLf
            End If
            
            'Else
            '    lvarQuery = lvarQuery & Mid(lvarControl.Name, 4) & "=""" & Replace(lvarControl.Text, """", """""") & """," & vbCrLf
            'End If
        End If
        If TypeName(lvarControl) = "CheckBox" And Trim(UCase(lvarControl.Name)) Like "CHKUSR*" Then
            If lvarControl.Value = 1 Then
                lvarQuery = lvarQuery & Mid(lvarControl.Name, 4) & "=true,"
            Else
                lvarQuery = lvarQuery & Mid(lvarControl.Name, 4) & "=false,"
            End If
        End If
        'TODO:
        'If TypeName(lvarControl) = "ComboBox" And Trim(UCase(lvarControl.Name)) Like "CMBFOR*" Then
        '    lvarQuery = lvarQuery & Mid(lvarControl.Name, 8, 3) & "_KEY" & "=""" & lvarControl.ItemData(lvarControl.ListIndex) & """," & vbCrLf
        'End If
    Next
    
    lvarQuery = Left(lvarQuery, Len(lvarQuery) - 3) & " WHERE USR_KEY = 1"
    'Quote Quotes =)~ (die bug die)
    'lvarQuery = Replace(lvarQuery, "'", "''")
    'InputBox lvarQuery, "Query?", lvarQuery
    'txtASS_INSURANCE = lvarQuery
    
    On Error GoTo errorhandler
    DBEngine.BeginTrans
    'MsgBox lvarQuery
    gvarDatabase.Execute lvarQuery, dbFailOnError
    DBEngine.CommitTrans
    
    MsgBox "Success Updating Company Details"
    Exit Sub
errorhandler:
    DBEngine.Rollback
    MsgBox DBEngine.Errors(0).Number & " - " & DBEngine.Errors(0).Description
    On Error GoTo 0
End Sub

Private Sub Fill_Form()
    Dim lvarRS0 As DAO.Recordset
    Dim lvarRS1 As DAO.Recordset
    Dim lvarControl As Control
    Dim lvarFSO As FileSystemObject
    'DBEngine.BeginTrans
    Set lvarRS0 = gvarDatabase.OpenRecordset("SELECT * FROM USER WHERE USR_KEY = 1", dbOpenForwardOnly)
    If lvarRS0.EOF Then
        'InValid
        'stsBar.SimpleText = "Please select a Valid Assessment"
        'Cancel = True
    Else
        'Valid
        'stsBar.SimpleText = ""
        'mvarASS_KEY = lvarRS0("ASS_KEY")
        For Each lvarControl In Controls
            If TypeName(lvarControl) = "TextBox" And UCase(lvarControl.Name) Like "???USR_*" Then
                'MsgBox Mid(lvarControl.Name, 4)
                lvarControl.Text = IIf(IsNull(lvarRS0(Mid(lvarControl.Name, 4))), "", lvarRS0(Mid(lvarControl.Name, 4)))
            ElseIf TypeName(lvarControl) = "CheckBox" And UCase(lvarControl.Name) Like "???USR_*" Then
                'MsgBox Mid(lvarControl.Name, 4)
                lvarControl.Value = IIf(lvarRS0(Mid(lvarControl.Name, 4)) = 0, 0, 1)
            'ElseIf TypeName(lvarControl) = "ComboBox" And UCase(lvarControl.Name) Like "???FOR_*" Then
                'TODO:look at tag for table and field to display
                'build list KEY FROM Control Name
                'if selected select
            ElseIf TypeName(lvarControl) = "Image" Then
                If IsNull(lvarRS0(Mid(lvarControl.Name, 4))) Then
                    Set lvarControl.Picture = LoadPicture
                Else
                    If lvarRS0(Mid(lvarControl.Name, 4)) <> "" Then
                        'TODO: Must get this to find local picture (only name in field) / just gened name
                        'Set lvarControl.Picture = LoadPicture(lvarRS0(Mid(lvarControl.Name, 4)))
                    Else
                        Set lvarControl.Picture = LoadPicture
                    End If
                End If
            ElseIf TypeName(lvarControl) = "CommandButton" Then
                'Nothing to be done with these
            End If
        Next
    End If
    
    
End Sub

Private Sub clear_form()
    Dim lvarControl As Control
        For Each lvarControl In Controls
            If TypeName(lvarControl) = "TextBox" Then
                lvarControl.Text = ""
            ElseIf TypeName(lvarControl) = "CheckBox" Then
                lvarControl.Value = 0
            'ElseIf TypeName(lvarControl) = "ComboBox" And lvarControl.Tag <> "" Then
            '    lvarControl.Clear
            ElseIf TypeName(lvarControl) = "ComboBox" Then
                lvarControl.Clear
            ElseIf TypeName(lvarControl) = "ListBox" Then
                lvarControl.Clear
            ElseIf TypeName(lvarControl) = "CommandButton" Then
            End If
        Next
End Sub
